// 小红书视频数据服务
export const mockXiaohongshuData = {
  // 视频列表数据
  videos: [
    {
      id: 'xhs8392742937',  // 小红书笔记ID格式
      title: '超火小红书穿搭分享',
      cover: '["http://sns-na-i6.xhscdn.com/1040g2sg31kjrrevlj0e05pdkoj9mhk2qa4ill6g?imageView2/2/w/1080/format/jpg&ap=1&sc=WB_CREATOR&sign=2b13e9b2af2c61ccca6115dc9e6c83eb&t=688c1041"]',
      shareUrl: 'https://www.xiaohongshu.com/explore/688b71910000000023029bab?xsec_token=YBl1v0HDBdBUE0n2lZaK8XKAzvaECR-D3TK-mnPsJNxEM=&xsec_source=pc_creatormng',
      author: {
        id: 'xhs5739204',
        name: '穿搭博主小红',
        avatar: 'https://sns-avatar-hw.xhscdn.com/avatar/user1.jpg',
        verified: true,
        level: '时尚达人',
      },
      stats: {
        views: '89.5万',
        likes: '5.3万',
        comments: '2089',
        collects: '1.2万',
        shares: '3421',
      },
      tags: ['穿搭', '时尚', '小红书'],
      description: '分享超火小红书穿搭，欢迎关注！#穿搭 #时尚搭配 #小红书穿搭',
      duration: '1:28',
      publishTime: '2024-03-20 15:30:00',
      status: 'normal',
      location: '上海',
    },
    {
      id: 'xhs8392742938',
      title: '探店｜这家店也太好吃了吧',
      cover: 'https://sns-img-hw.xhscdn.com/content-img/cover2.jpg',
      shareUrl: 'https://www.xiaohongshu.com/discovery/item/66ff645e000000001902f595?source=webshare&xhsshare=pc_web&xsec_token=ABazVPmmVQzh5ZTrq2OVnb0r_iSuztW3SoneurwP18jH8=&xsec_source=pc_share',
      author: {
        id: 'xhs5739205',
        name: '吃货小分队',
        avatar: 'https://sns-avatar-hw.xhscdn.com/avatar/user2.jpg',
        verified: true,
        level: '美食达人',
      },
      stats: {
        views: '56.8万',
        likes: '3.9万',
        comments: '1567',
        collects: '8900',
        shares: '2345',
      },
      tags: ['美食', '探店', '生活'],
      description: '这家藏在巷子里的店也太好吃了！人均88，人少排队短，强烈推荐！#美食探店 #上海美食 #小红书探店',
      duration: '2:24',
      publishTime: '2024-03-20 14:20:00',
      status: 'normal',
      location: '上海',
    },
  ],

  // 获取视频列表
  getVideoList() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          list: this.videos,
          total: this.videos.length,
        })
      }, 300)
    })
  },

  // 获取视频详情
  getVideoDetail(id) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const video = this.videos.find((v) => v.id === id)
        if (video) {
          resolve(video)
        } else {
          reject(new Error('笔记不存在'))
        }
      }, 200)
    })
  },

  // 获取视频统计数据
  getVideoStats(id) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const video = this.videos.find((v) => v.id === id)
        if (video) {
          // 模拟实时数据变化
          const randomIncrease = (num) => {
            const base = parseInt(num.replace(/[^\d]/g, ''))
            return base + Math.floor(Math.random() * 100)
          }

          resolve({
            ...video.stats,
            views: randomIncrease(video.stats.views),
            likes: randomIncrease(video.stats.likes),
            comments: randomIncrease(video.stats.comments),
          })
        }
      }, 200)
    })
  },

  // 获取相关视频
  getRelatedVideos(id, limit = 5) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const currentVideo = this.videos.find((v) => v.id === id)
        const relatedVideos = this.videos
          .filter(
            (v) =>
              v.id !== id &&
              v.tags.some((tag) => currentVideo.tags.includes(tag)),
          )
          .slice(0, limit)
        resolve(relatedVideos)
      }, 400)
    })
  },

  // 构建小红书播放器URL
  getVideoUrl(video) {
    return video.shareUrl || video.videoUrl || `https://www.xiaohongshu.com/explore/${video.id}`
  },

  // 模拟视频播放进度
  getVideoProgress(id) {
    return new Promise((resolve) => {
      const progress = localStorage.getItem(`xhs-video-progress-${id}`) || '0'
      resolve(parseInt(progress))
    })
  },

  // 保存视频播放进度
  saveVideoProgress(id, progress) {
    return new Promise((resolve) => {
      localStorage.setItem(`xhs-video-progress-${id}`, progress.toString())
      resolve(true)
    })
  },
}